/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.log.login.controller.assembler;

import com.google.common.collect.Lists;
import net.siufung.core.utils.CopyUtil;
import net.siufung.market.base.log.login.controller.model.vo.LoginLogVo;
import net.siufung.market.base.log.login.mapper.entity.LoginLog;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;

/**
 *
 * 系统日志表 持久层展示层组装器
 *
 * @author 陈建峰
 * @since 2022-07-04 17:54:53
 */
public class LoginLogAssembler {

    /**
     * LoginLog 转换成 LoginLogVo
     * @param log 数据库实体
     * @return LoginLogVo 视图
     */
    public static LoginLogVo from(LoginLog log){
        if(!Objects.isNull(log)){
            LoginLogVo logVo = new LoginLogVo();
            CopyUtil.copyProperties(log, logVo);
            return logVo;
        }
        return null;
    }

    /**
     * LogList 转换成 LogVoList
     * @param logList 数据库实体集合
     * @return List<LoginLogVo> 视图集合
     */
    public static List<LoginLogVo> fromList(List<LoginLog> logList){
        List<LoginLogVo> logVoList = Lists.newArrayList();
        if(!CollectionUtils.isEmpty(logList)){
            LoginLogVo logVo;
            for (LoginLog log: logList) {
                logVo = new LoginLogVo();
                CopyUtil.copyProperties(log, logVo);
                logVoList.add(logVo);
            }
        }
        return logVoList;
    }
}

